package generated.rmo.utils;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class EntityManagerFactorySingleton {
	private static EntityManagerFactory emf = Persistence.createEntityManagerFactory("transactions-optional");
	
	private static ThreadLocalEntityManager tl = new ThreadLocalEntityManager();

	
	private static class ThreadLocalEntityManager extends ThreadLocal<EntityManager> {
	    public EntityManager initialValue() {
	      return EntityManagerFactorySingleton.emf.createEntityManager();
	    }
	}

	
    public static EntityManager getEntityManager()
    {
    	return tl.get();
    }
}